package com.lzy.cloud.ticket.train.controller;

import com.lzy.cloud.ticket.train.facade.SearchFacade;
import com.lzy.cloud.ticket.train.facade.TrainFacade;
import com.lzy.cloud.ticket.train.facade.UserFacade;
import com.lzy.cloud.ticket.train.request.app.OrderOfflineRefundAppRequest;
import com.lzy.cloud.ticket.train.request.app.SearchAppRequest;
import com.lzy.cloud.ticket.train.request.app.UserInfoAppRequest;
import com.lzy.framework.core.ensure.Ensure;
import com.lzy.framework.core.output.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping(value = "/train")
public class TrainController extends BaseController {

    @Autowired
    private SearchFacade searchFacade;

    @Autowired
    private TrainFacade trainFacade;

    @Autowired
    private UserFacade userFacade;

    /**
     * 余票查询
     *
     * @return
     */
    @RequestMapping(value = "/ticket/search", method = RequestMethod.POST)
    public Result search(@RequestBody SearchAppRequest searchAppRequest) {
        Result result = searchFacade.queryTicketsFilter(searchAppRequest);
        Ensure.that(result.getResult()).isNotNull("00010001");
        return result;
    }


    /**
     * 线下退款
     *
     * @return
     * @TODO 未测试
     */
    @RequestMapping(value = "/refund/offline", method = RequestMethod.POST)
    public Result offlineRefund(@RequestBody OrderOfflineRefundAppRequest orderOfflineRefundAppRequest) {
        Result result = trainFacade.offlineRefund(orderOfflineRefundAppRequest);
        return result;
    }

    /**
     * 12306身份验证
     *
     * @returns
     * @TODO 未测试
     */
    @RequestMapping(value = "/check/12306", method = RequestMethod.POST)
    public Result checkAccount(@RequestBody UserInfoAppRequest userInfoAppRequest) {
        Result result = userFacade.checkAccount(userInfoAppRequest);
        return result;
    }



}
